{template header}

<link href="{SITE_URL}public/bootstrap-datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="{SITE_URL}public/bootstrap-datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript" src="{SITE_URL}public/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>


<div class="container">


<ol class="breadcrumb">
  <li><a href="{SITE_URL}">首页</a></li>
  <li><a href="{tsUrl('event')}">活动</a></li>
  <li><a href="{tsUrl('event','show',array('id'=>$strEvent[eventid]))}">{$strEvent['title']}</a></li>
  <li class="active">修改活动</li>
</ol>



<div class="panel panel-default">
  <div class="panel-body">
  



<div class="row">
  <div class="col-md-2"></div>
  <div class="col-md-8">
  
  <form id='form1' method="POST" action="{SITE_URL}index.php?app=event&ac=edit&ts=basedo"  enctype="multipart/form-data">

  <div class="form-group">
    <label>标题：</label>
    <input name="title" type="text" class="form-control" value="{$strEvent['title']}">
  </div>
  
  
 {if $arrType} 
  <div class="form-group">
    <label>类型：</label>

<select class="form-control" name="typeid">
{loop $arrType $key $item}
<option value="{$item[typeid]}" {if $item[typeid]==$strEvent[typeid]}selected="select"{/if}>{$item[typename]}</option>
{/loop}
</select>
  </div>
  
  {/if}
  
  
  <div class="form-group">
    <label>开始时间：</label>
    <p><input class="form-control" name="starttime" readonly value=" {php echo date('Y-m-d H:i',$strEvent[starttime])}" id="beginTime" />
	</p>
  </div>

    <div class="form-group">
      <label>结束时间：</label>
      <p><input class="form-control" name="endtime" readonly value=" {php echo date('Y-m-d H:i',$strEvent[endtime])}" id="endTime" /></p>
    </div>

    <div class="form-group">
      <label>报名期限：</label>
      <p><input class="form-control" name="limittime" readonly value=" {php echo date('Y-m-d H:i',$strEvent[limittime])}" id="limitTime" /></p>
    </div>

    <div class="form-group">
      <label>名额（0表示不限）：</label>
      <p><input class="form-control" name="quota" value="{$strEvent['quota']}" /> </p>
    </div>


    <div class="form-group">
      <label>报名资格（0表示不要求）：</label>
      <p>服务时长不少于<input class="form-control" name="duty" value="{$strEvent['duty']}" /> </p>
    </div>

      <div class="form-group">
          <label>费用：</label>
          <p><input class="form-control" name="price" value="{$strEvent['price']}" /> </p>
      </div>
  
  <div class="form-group">
    <label>地点：</label>
    <p><input class="form-control" name="address" value="{$strEvent[address]}" /> (例如：北京市朝阳区三里屯工人体育馆)</p>
  </div>
  
  <div class="form-group">
    <label>坐标：</label>
    <p><input class="form-control" id="gps" name="coordinate" readonly value="{$strEvent[coordinate]}" /> <a onclick="openmap();" href="javascript:void('0');">点击从地图中选择</a> (例如：30.238747,120.14532)</p>
  </div>
  
  <div class="form-group">
    <label>封面：</label>
    <div class="">
       <img 
          id="picshow" 
          valign="middle" 
          src="{if $strEvent[photo]}{php echo tsXimg($strEvent[photo],'event',500,'',$strEvent[path])}{else}{SITE_URL}app/event/skins/default/event.jpg{/if}" 
          style="height: 150px;">
       <div style="display: flex;">
         <input type="file" id="picfile" name="picfile">
         <div id="picsubmit" class="btn btn-success">上传照片</button> 
         <input type="hidden" name="photo" id="photo" value="{$strEvent['photo']}" />
       </div>
    </div>
  </div>

  
  <div class="form-group">
    <label>内容：</label>
    <div id="tseditor">{$strEvent[content]}</div>
    <div style="display: none;">
     <textarea id="content" name="content">{$strEvent[content]}</textarea>
    </div>
    <!--<textarea name="content" id="tseditor"></textarea>-->

  </div>


  
<input type="hidden" name="eventid" value="{$strEvent[eventid]}" />
  <input class="btn btn-success" type="submit" value="修改活动">  <a href="{tsUrl('event','show',array('id'=>$strEvent[eventid]))}">返回</a>
  
</form>

</div>
</div>


</div>
</div>
</div>

{php doAction('tseditor')}

<script src="{SITE_URL}public/js/image.js"></script>
<script>
  $(function(e){
    $('#form1').on('submit', function(e) {
      var title  = $('#title').val();
      var starttime  = $('#startTime').val();
      var endtime  = $('#endTime').val();
      var limittime  = $('#limitTime').val();
      var content  = $('#content').val();

      var quota  = $('#quota').val();



      if(title==''){
        bootbox.alert('名称必填');
        return false;
      }

      if(limittime==''){
        bootbox.alert('报名截止时间必填');
        return false;
      }

      if(starttime==''){
        bootbox.alert('开始时间必填');
        return false;
      }

      if(endtime==''){
        bootbox.alert('结束时间必填');
        return false;
      }
      if (content == '<p><br></p>') {
        bootbox.alert('内容不能为空');
        return false;
      }


    });

    var picFile = null;
    // 封面上传监听
    $('#picfile').on("change", function (e) {
      $("#photo").val('')
      $("#picshow").attr('src', ''); 

      let file = e.target.files[0]
      compressImg(file, 0.25).then(res => {
        $("#picshow").attr('src', window.URL.createObjectURL(res.file)); 
        picFile = res.file
      })
    });
    
    var upload_url = "{SITE_URL}index.php?app=event&ac=do&ts=photo";
    $('#picsubmit').on("click", function () {
      if (!picFile) {
        return bootbox.alert('请选择图片！');
      }
      var formData = new FormData();
      formData.append("file", picFile, picFile.filename);
      formData.append("upload_file", true);
      console.log(formData, picFile)
      $.ajax({
        url: upload_url,
        data: formData,
        processData: false,
        contentType: false,
        type: 'POST',
        success: function(data){
          if (data != 0) {
            $("#photo").val(data)
            picFile = null
              return bootbox.alert('图片上传成功！');
          } else {
              return bootbox.alert('图片上传失败！');
          }
        }
      });
    });

  });

  function insertGps(dd){
    $('#gps').val(dd);
    $('#myModal').modal('hide');
  }
  function openmap(){
    tsNotice('<iframe frameborder="0" scrolling="no" width="100%" height="400" src="{SITE_URL}index.php?app=event&ac=add&ts=map"></iframe>');
  }


  $('#beginTime').datetimepicker({
    language:  'zh-CN',
    autoclose: true,
    format: 'yyyy-mm-dd hh:ii'
  });

  $('#endTime').datetimepicker({
    language:  'zh-CN',
    autoclose: true,
    format: 'yyyy-mm-dd hh:ii'
  });

  $('#limitTime').datetimepicker({
    language:  'zh-CN',
    autoclose: true,
    format: 'yyyy-mm-dd hh:ii'
  });

</script>
{template footer}